import { ref } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { showModal, toast } from '@/utils/utils'
import { useFullscreen } from '@vueuse/core'


// 组合式API导出
export function usePugHeaderFunc(updatePwdRef) {


    const { isFullscreen, toggle } = useFullscreen()
    var store = useStore();
    var router = useRouter();


    const handleCommand = (res) => {
        if (res == 'logout') {
            logout()
        }

        if (res == 'updatepwd') {
            updatePwdRef.value.open();
        }
    };

    // 刷新
    const handleRefresh = () => {
        window.location.reload();
    }

    // 首页
    const handleIndex = () => {
        router.push("/");
    }

    // 折叠
    const handleExpand = () => {
        store.commit("menu/handleSlideWidth");
    }

    // 全屏
    const handleFulling = () => {
        toggle();
    }

    // 退出登录
    const logout = () => {
        showModal("你确定退出登录吗").then(res => {
            store.dispatch("login/logout").then(res => {
                router.push("/login")
                toast("退出登录成功")
            })
        })
    }


    return {
        handleCommand,
        handleRefresh,
        handleIndex,
        handleExpand,
        handleFulling,
        isFullscreen
    }
}